//
//  MHProfileHeaderCell.m
// MiaoCircle
//
//Created by acgera on 2018/4/9.
//  Copyright © 2018年 acgera. All rights reserved.
//

#import "MHProfileHeaderCell.h"
#import "MHCommonProfileHeaderItemViewModel.h"
@interface MHProfileHeaderCell ()

/// 头像
@property (weak, nonatomic) IBOutlet UIImageView *avatarView;
/// 昵称
@property (weak, nonatomic) IBOutlet UILabel *nicknameLabel;
/// 微信号
@property (weak, nonatomic) IBOutlet UILabel *wechatNumLabel;

/// viewModel
@property (nonatomic, readwrite, strong) MHCommonProfileHeaderItemViewModel *viewModel;
@end

@implementation MHProfileHeaderCell

#pragma mark - Public Method
+ (instancetype)cellWithTableView:(UITableView *)tableView{
    static NSString *ID = @"ProfileHeaderCell";
    MHProfileHeaderCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (!cell) cell = [self mh_viewFromXib];
    return cell;
}

- (void)bindViewModel:(MHCommonProfileHeaderItemViewModel *)viewModel{
    self.viewModel = viewModel;
    @weakify(self);
    [RACObserve([MHHTTPService sharedInstance].currentUser, allHeadPath) subscribeNext:^(NSString  *headUrl) {
        @strongify(self);
        if (headUrl.length > 0) {
            [self.avatarView yy_setImageWithURL:[NSURL URLWithString:headUrl] placeholder:MHDefaultAvatar(MHDefaultAvatarTypeDefualt)];
        }
        
    }];
    
    [RACObserve([MHHTTPService sharedInstance].currentUser, screenName) subscribeNext:^(NSString  *screenName) {
        @strongify(self);
         self.nicknameLabel.text = screenName;
    }];
//    [self.avatarView yy_setImageWithURL:[NSURL URLWithString:viewModel.user.headPic] placeholder:MHDefaultAvatar(MHDefaultAvatarTypeDefualt)];
//    self.nicknameLabel.text = viewModel.user.nickName;
    self.wechatNumLabel.textColor = MHButtonDisableBgColor;
    self.nicknameLabel.textColor = MHMainTextColor;
    self.wechatNumLabel.text = [NSString stringWithFormat:@"ID: %@",viewModel.user.uniqueID];
    
    
}
/// 防止Crash
- (void)setIndexPath:(NSIndexPath *)indexPath rowsInSection:(NSInteger)rows{}

#pragma mark - Privite Method
- (void)awakeFromNib {
    [super awakeFromNib];
    self.contentView.backgroundColor = [UIColor whiteColor];
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
}


@end
